package com.zsc.wxapp.services.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zsc.wxapp.entity.PowerGroup;
import com.zsc.wxapp.entity.dto.AnnouncementDTO;
import com.zsc.wxapp.entity.dto.PowerGroupDTO;
import com.zsc.wxapp.entity.vo.ManagerVO;
import com.zsc.wxapp.entity.vo.RoleVO;
import com.zsc.wxapp.mapper.PowerGroupMapper;
import com.zsc.wxapp.services.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

@Service
public class AdminServiceImpl implements AdminService {
    @Autowired
    private PowerGroupMapper powerGroupMapper;

    /**
     * 添加权限组
     * @param powerGroupDTO
     */
    @Override
    public void addPowerGroup(PowerGroupDTO powerGroupDTO) {
        Integer num = powerGroupMapper.getNum();
        powerGroupMapper.addPowerGroup(powerGroupDTO,num+1);
    }

    /**
     * 获得权限组
     * @return
     */
    @Override
    public List<PowerGroup> getPowerGroup() {
        List<PowerGroup> powerGroups = powerGroupMapper.getPowerGroup();
        for (PowerGroup powerGroup :powerGroups){
            Integer num = powerGroupMapper.getPowerGroupNum(powerGroup.getPowerGroupId());
            powerGroup.setPowerNumber(num);
        }
        return powerGroups;
    }

    /**
     * 删除权限组
     * @param ids
     */
    @Override
    public void deletePowerGroup(List<Integer> ids) {
        powerGroupMapper.deletePowerGroup(ids);
    }

    /**
     * 获取对应权限用户
     * @return
     */
    @Override
    public List<RoleVO> getRole(Integer roleId) {
        List<RoleVO> roleVOS = powerGroupMapper.getRole(roleId);
        for (RoleVO roleVO:roleVOS ){
            String groupName = powerGroupMapper.getGroupName(roleVO.getGroupId());
            roleVO.setPowerGroupName(groupName);
        }
        return roleVOS;

    }

    /**
     * 获取经理
     * @return
     */
    @Override
    public List<ManagerVO> getManager() {
        Set<ManagerVO> manager = powerGroupMapper.getManager();
        ArrayList<ManagerVO> name = new ArrayList<>(manager);
        return name;
    }
}
